////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file   CollabRCBotUnitTests\TestArithmeticMeanTreeNode.h
///
/// @brief  Defines the tests for CollabRC::Bot::AI::ArithmeticMeanTreeNode
////////////////////////////////////////////////////////////////////////////////////////////////////

#include <cxxtest/TestSuite.h>
#include "../CollabRCBot/ArithmeticMeanTreeNode.h"
#include "MockConstantTreeNode.h"
#include "MockOperationTreeNode.h"

using CollabRC::Bot::AI::ArithmeticMeanTreeNode;

class TestArithmeticMeanTreeNode : public CxxTest::TestSuite
{
private:
    MockConstantTreeNode m_lhs, m_rhs;
public:
    /** @brief creates a new test suite for CollabRC::Bot::AI::ArithmeticMeanTreeNode */
    TestArithmeticMeanTreeNode():m_lhs(4),m_rhs(6) { };

    /**
     * @brief Tests the PerformOperation() method
     */
    void TestPerformPerformOperation()
    {
        ArithmeticMeanTreeNode node(m_lhs, m_rhs);
        TS_ASSERT_EQUALS(node.PerformOperation(4.0f, 6.0f), 5.0f);
        TS_ASSERT_EQUALS(node.PerformOperation(4.0f, 5.0f), 4.5f);
        TS_ASSERT_EQUALS(node.PerformOperation(-1.0f, 1.0f), 0.0f);
    }

    /** @brief Tests the Clone() method */
    void TestClone()
    {
        ArithmeticMeanTreeNode node(m_lhs, m_rhs);
        ArithmeticMeanTreeNode* clone = dynamic_cast<ArithmeticMeanTreeNode*>(node.Clone());
        TS_ASSERT(clone != NULL);
        TS_ASSERT_EQUALS(clone->Compute(), node.Compute());
        TS_ASSERT_THROWS_NOTHING(delete clone);
    }

    /** @brief Tests the clonability from another operation */
    void TestMutation()
    {
        MockOperationTreeNode op(m_lhs, m_rhs);
        ArithmeticMeanTreeNode node(op);
        TS_ASSERT_EQUALS(node.Compute(), node.PerformOperation(m_lhs.Compute(), m_rhs.Compute()));
    }
};
